import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Solution1 {
    public static void main(String[] args) {
        Queue<Integer> queue=new ArrayDeque<>();
        int temp;
        boolean flag;
        Scanner s=new Scanner(System.in);
        int t=s.nextInt();
        while(t-->0){
            int q=s.nextInt();
            s.nextLine();
            while(q-->0){
                String command=s.nextLine();
                switch (command){
                    case "TOP":
                        temp=queue.isEmpty()?-1:queue.peek();
                        System.out.println(temp);
                        break;
                    case "POP":
                        flag=queue.isEmpty();
                        if(flag)
                            System.out.println(-1);
                        else
                            queue.poll();
                        break;
                    case "SIZE":
                        System.out.println(queue.size());
                        break;
                    case "CLEAR":
                        queue.clear();
                        break;
                    default:
                        queue.add(Integer.valueOf(command.split(" ")[1]));
                }
            }
        }
    }



}
/*
2
7
PUSH 1
PUSH 2
TOP
POP
TOP
POP
POP
5
PUSH 1
PUSH 2
SIZE
POP
SIZE
 */